@@ -32,6 +32,7 @@ |
||
32 | 32 |
<script src="scripts/services/thumbnail-service.js"></script> |
33 | 33 |
<script src="scripts/services/prefs-service.js"></script> |
34 | 34 |
<script src="scripts/services/date-formatter.js" charset="utf-8"></script> |
35 |
+ <script src="scripts/directives/right-click-directive.js"></script> |
|
35 | 36 |
|
36 | 37 |
|
37 | 38 |
|
@@ -36,53 +36,9 @@ angular.module('codexApp.index', []) |
||
36 | 36 |
}); |
37 | 37 |
|
38 | 38 |
var remote = require('remote') |
39 |
- var Menu = remote.require('menu') |
|
40 |
- var MenuItem = remote.require('menu-item') |
|
41 |
- |
|
42 |
- // Build our new menu |
|
43 |
- var menu = new Menu() |
|
44 |
- menu.append(new MenuItem({ |
|
45 |
- label: "append", |
|
46 |
- click: function() { |
|
47 |
- // Trigger an alert when menu item is clicked |
|
48 |
- alert('Deleted') |
|
49 |
- } |
|
50 |
- })) |
|
51 |
- menu.append(new MenuItem({ |
|
52 |
- label: 'More Info...', |
|
53 |
- click: function() { |
|
54 |
- // Trigger an alert when menu item is clicked |
|
55 |
- alert('Here is more information') |
|
56 |
- } |
|
57 |
- })) |
|
58 |
- |
|
59 |
- // Add the listener |
|
60 |
- document.addEventListener('DOMContentLoaded', function () { |
|
61 |
- document.querySelector('.js-context-menu').addEventListener('click', function (event) { |
|
62 |
- menu.popup(remote.getCurrentWindow()); |
|
63 |
- }) |
|
64 |
- }) |
|
65 |
- |
|
66 |
- |
|
67 |
- |
|
68 |
- |
|
69 |
- var holder = document.getElementById('holder'); |
|
70 |
- holder.ondragover = function () { |
|
71 |
- return false; |
|
72 |
- }; |
|
73 |
- holder.ondragleave = holder.ondragend = function () { |
|
74 |
- return false; |
|
75 |
- }; |
|
76 |
- holder.ondrop = function (e) { |
|
77 |
- e.preventDefault(); |
|
78 |
- var file = e.dataTransfer.files[0]; |
|
79 |
- console.log('File you dragged here is', file.path); |
|
80 |
- document.getElementById('image-container').src = file.path |
|
81 |
- return false; |
|
82 |
- }; |
|
83 | 39 |
|
84 | 40 |
$scope.openFile = function(file){ |
85 |
- console.log("openning " + file.type + " link: " + file.path); |
|
41 |
+ console.log("-> Openning " + file.type + " link: " + file.path); |
|
86 | 42 |
switch (file.type) { |
87 | 43 |
case "Markdown": |
88 | 44 |
FileService.setCurrentNote(file) |
@@ -95,7 +51,17 @@ angular.module('codexApp.index', []) |
||
95 | 51 |
$scope.setView(); |
96 | 52 |
break; |
97 | 53 |
} |
54 |
+ } |
|
98 | 55 |
|
56 |
+ $scope.editFile = function(file){ |
|
57 |
+ console.log("-> Editing " + file.type + " link: " + file.path); |
|
58 |
+ switch (file.type) { |
|
59 |
+ case "Markdown": |
|
60 |
+ FileService.setCurrentNote(file) |
|
61 |
+ $rootScope.$broadcast('main-window:note-edit'); |
|
62 |
+ $state.go("note-edit"); |
|
63 |
+ break; |
|
64 |
+ } |
|
99 | 65 |
} |
100 | 66 |
|
101 | 67 |
$rootScope.$on('file-service:files-loaded', function(){ |
@@ -145,7 +111,20 @@ angular.module('codexApp.index', []) |
||
145 | 111 |
} else { |
146 | 112 |
return ""; |
147 | 113 |
} |
148 |
- |
|
149 | 114 |
} |
150 | 115 |
|
116 |
+ var Menu = remote.require('menu'); |
|
117 |
+ var MenuItem = remote.require('menu-item'); |
|
118 |
+ var currentWindow = remote.getCurrentWindow(); |
|
119 |
+ |
|
120 |
+ $scope.fileContextMenu = function (file) { |
|
121 |
+ var menu = new Menu(); |
|
122 |
+ menu.append(new MenuItem({ label: 'Open File', click: function () { |
|
123 |
+ $scope.openFile(file); |
|
124 |
+ } })); |
|
125 |
+ menu.append(new MenuItem({ label: 'Edit File', click: function () { |
|
126 |
+ $scope.editFile(file); |
|
127 |
+ } })); |
|
128 |
+ menu.popup(currentWindow); |
|
129 |
+ } |
|
151 | 130 |
}]); |
@@ -101,4 +101,16 @@ angular.module('codexApp.header', []) |
||
101 | 101 |
} |
102 | 102 |
}); |
103 | 103 |
|
104 |
+ $rootScope.$on('main-window:note-edit', function() { |
|
105 |
+ if(!$scope.$$phase) { |
|
106 |
+ $scope.$apply(function(){ |
|
107 |
+ $scope.noteViewBtnClass = ""; |
|
108 |
+ $scope.noteEditBtnClass = "active"; |
|
109 |
+ }); |
|
110 |
+ } else { |
|
111 |
+ $scope.noteViewBtnClass = ""; |
|
112 |
+ $scope.noteEditBtnClass = "active"; |
|
113 |
+ } |
|
114 |
+ }); |
|
115 |
+ |
|
104 | 116 |
}]); |
@@ -11,10 +11,8 @@ angular.module('codexApp.noteEdit', []) |
||
11 | 11 |
.controller('NoteEditCtrl',['$scope', '$rootScope', '$state', 'FileService', function ($scope, $rootScope, $state, FileService) { |
12 | 12 |
|
13 | 13 |
$scope.note = FileService.getCurrentNote(); |
14 |
- $scope.container = "note-container"; |
|
15 |
- $scope.raw_data = $scope.note.data; |
|
16 |
- $scope.savedBeforeQuit = false; |
|
17 | 14 |
console.log('-> Editing File: ' + $scope.note.path) |
15 |
+ $scope.savedBeforeQuit = false; |
|
18 | 16 |
|
19 | 17 |
$rootScope.$on('window-view:change', function() { |
20 | 18 |
if($scope.raw_data != "" && $scope.raw_data != undefined) { |
@@ -26,13 +24,34 @@ angular.module('codexApp.noteEdit', []) |
||
26 | 24 |
|
27 | 25 |
}); |
28 | 26 |
|
27 |
+ $scope.loadFile = function() { |
|
28 |
+ var fs = require('fs'); |
|
29 |
+ fs.readFile($scope.note.path, function(err, data) { |
|
30 |
+ $scope.note.data = new Buffer(data).toString('utf8') |
|
31 |
+ if(!$scope.$$phase) { |
|
32 |
+ $scope.$apply(function(){ |
|
33 |
+ $scope.raw_data = $scope.note.data; |
|
34 |
+ }); |
|
35 |
+ } else { |
|
36 |
+ $scope.raw_data = $scope.note.data; |
|
37 |
+ } |
|
38 |
+ }); |
|
39 |
+ console.log($scope.raw_data); |
|
40 |
+ } |
|
41 |
+ |
|
42 |
+ if($scope.note.data != undefined || $scope.note.data != ""){ |
|
43 |
+ $scope.loadFile(); |
|
44 |
+ } else { |
|
45 |
+ $scope.raw_data = $scope.note.data; |
|
46 |
+ } |
|
47 |
+ |
|
29 | 48 |
$scope.aceLoaded = function(_editor) { |
30 | 49 |
_editor.setReadOnly(false); |
31 | 50 |
//console.log($scope.raw_data); |
32 | 51 |
}; |
33 | 52 |
|
34 | 53 |
$scope.aceChanged = function(e) { |
35 |
- console.log("-> Note data changed."); |
|
54 |
+ //console.log("-> Note data changed."); |
|
36 | 55 |
}; |
37 | 56 |
|
38 | 57 |
}]); |
@@ -0,0 +1,12 @@ |
||
1 |
+angular.module('codexApp') |
|
2 |
+.directive('ngRightClick', function($parse) { |
|
3 |
+ return function(scope, element, attrs) { |
|
4 |
+ var fn = $parse(attrs.ngRightClick); |
|
5 |
+ element.bind('contextmenu', function(event) { |
|
6 |
+ scope.$apply(function() { |
|
7 |
+ event.preventDefault(); |
|
8 |
+ fn(scope, {$event:event}); |
|
9 |
+ }); |
|
10 |
+ }); |
|
11 |
+ }; |
|
12 |
+}); |
@@ -22,7 +22,7 @@ |
||
22 | 22 |
<div class="file-view"> |
23 | 23 |
<ul> |
24 | 24 |
<li ng-repeat="file in files track by $index" ng-dblclick="openFile(file)" class="file-view-item"> |
25 |
- <div class="thumbnail-icon" ng-show="file.type != 'Folder'"> |
|
25 |
+ <div class="thumbnail-icon" ng-show="file.type != 'Folder'" ng-right-click="fileContextMenu(file)"> |
|
26 | 26 |
<img src="{{getImageURL(file.path)}}" ng-hide="isImage(file.type)"> |
27 | 27 |
<img src="{{file.thumbnail}}" ng-show="isImage(file.type)"> |
28 | 28 |
</div> |